/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telaCadastros;

import java.awt.event.KeyEvent;
import managertelaCadastros.managerCadProduto;
import telasMensagem.MensagemConfirmacao;
import util.Mensagem;

/**
 *
 * @author fumio
 */
public class CadProduto extends javax.swing.JDialog {

    private static CadProduto cadProduto;
    private static managerCadProduto managerCadProduto;

    /**
     * Creates new form CadGeneric
     */
    public CadProduto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setTitle("Cadastro de Produto");
    }

    public static CadProduto getInstance(managerCadProduto mCadProduto) {
        cadProduto = new CadProduto(null, true);
        managerCadProduto = mCadProduto;
        return cadProduto;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        edtCodigo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        edtProduto = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        edtPrecoCusto = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        edtPrecoVenda = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        edtEstoqueMinimo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        edtQuantidade = new javax.swing.JTextField();
        edtCodFabricante = new javax.swing.JTextField();
        btnPesquisarFabricante = new javax.swing.JButton();
        edtFabricante = new javax.swing.JTextField();
        edtCodClassificacao = new javax.swing.JTextField();
        btnPesquisarClassificacao = new javax.swing.JButton();
        edtClassificacao = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        btnConfirmar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Código");
        jLabel1.setPreferredSize(new java.awt.Dimension(119, 17));
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 20, 77, -1));

        edtCodigo.setEditable(false);
        edtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtCodigoActionPerformed(evt);
            }
        });
        jPanel1.add(edtCodigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 38, 77, 30));

        jLabel2.setText("Produto");
        jLabel2.setPreferredSize(new java.awt.Dimension(119, 17));
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 80, 92, -1));

        edtProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtProdutoActionPerformed(evt);
            }
        });
        jPanel1.add(edtProduto, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 101, 575, 30));

        jLabel3.setText("Fabricante");
        jLabel3.setPreferredSize(new java.awt.Dimension(119, 17));
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 150, 98, -1));

        jLabel4.setText("Classificação");
        jLabel4.setPreferredSize(new java.awt.Dimension(119, 17));
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 210, -1, -1));
        jPanel1.add(edtPrecoCusto, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 290, 126, 30));

        jLabel5.setText("Preço Custo");
        jLabel5.setPreferredSize(new java.awt.Dimension(119, 17));
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 270, -1, -1));

        jLabel6.setText("Preço Venda");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 280, -1, -1));
        jPanel1.add(edtPrecoVenda, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 310, 126, 30));

        jLabel7.setText("Estoque Mínimo");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 330, -1, -1));
        jPanel1.add(edtEstoqueMinimo, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 350, 126, 30));

        jLabel8.setText("Quantidade");
        jLabel8.setPreferredSize(new java.awt.Dimension(97, 17));
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 340, -1, -1));
        jPanel1.add(edtQuantidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 360, 126, 30));

        edtCodFabricante.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                edtCodFabricanteKeyPressed(evt);
            }
        });
        jPanel1.add(edtCodFabricante, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 166, 63, 30));

        btnPesquisarFabricante.setText("P");
        btnPesquisarFabricante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarFabricanteActionPerformed(evt);
            }
        });
        jPanel1.add(btnPesquisarFabricante, new org.netbeans.lib.awtextra.AbsoluteConstraints(101, 166, 61, 30));
        jPanel1.add(edtFabricante, new org.netbeans.lib.awtextra.AbsoluteConstraints(169, 167, 440, 30));

        edtCodClassificacao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                edtCodClassificacaoKeyPressed(evt);
            }
        });
        jPanel1.add(edtCodClassificacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 232, 63, 30));

        btnPesquisarClassificacao.setText("P");
        btnPesquisarClassificacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarClassificacaoActionPerformed(evt);
            }
        });
        jPanel1.add(btnPesquisarClassificacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(102, 232, 61, 30));
        jPanel1.add(edtClassificacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(169, 233, 440, 30));

        jPanel2.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnConfirmar.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });
        jPanel2.add(btnConfirmar, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 10, 120, 75));

        btnCancelar.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jPanel2.add(btnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, 120, 75));

        btnSair.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        btnSair.setText("Sair");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel2.add(btnSair, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 10, 120, 75));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 634, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-644)/2, (screenSize.height-540)/2, 644, 540);
    }// </editor-fold>//GEN-END:initComponents

    private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed
        // TODO add your handling code here:

        MensagemConfirmacao msg = new MensagemConfirmacao(null, rootPaneCheckingEnabled);
        if (Mensagem.confirmarCadastro("Produto")) {
            managerCadProduto.salvar();
            LimpaTela();
        }
    }//GEN-LAST:event_btnConfirmarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        LimpaTela();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    private void edtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtCodigoActionPerformed

    private void edtProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtProdutoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtProdutoActionPerformed

    private void btnPesquisarFabricanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarFabricanteActionPerformed
        // TODO add your handling code here:
        managerCadProduto.pesquisaFabricante();
    }//GEN-LAST:event_btnPesquisarFabricanteActionPerformed

    private void btnPesquisarClassificacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarClassificacaoActionPerformed
        // TODO add your handling code here:
        managerCadProduto.pesquisaClassificacao();
    }//GEN-LAST:event_btnPesquisarClassificacaoActionPerformed

    private void edtCodFabricanteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_edtCodFabricanteKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            managerCadProduto.buscaFabricante(Integer.parseInt(edtFabricante.getText()));
        }
    }//GEN-LAST:event_edtCodFabricanteKeyPressed

    private void edtCodClassificacaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_edtCodClassificacaoKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            managerCadProduto.buscaClassificacao(Integer.parseInt(edtClassificacao.getText()));
        }

    }//GEN-LAST:event_edtCodClassificacaoKeyPressed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConfirmar;
    public javax.swing.JButton btnPesquisarClassificacao;
    public javax.swing.JButton btnPesquisarFabricante;
    private javax.swing.JButton btnSair;
    public javax.swing.JTextField edtClassificacao;
    public javax.swing.JTextField edtCodClassificacao;
    public javax.swing.JTextField edtCodFabricante;
    public javax.swing.JTextField edtCodigo;
    public javax.swing.JTextField edtEstoqueMinimo;
    public javax.swing.JTextField edtFabricante;
    public javax.swing.JFormattedTextField edtPrecoCusto;
    public javax.swing.JFormattedTextField edtPrecoVenda;
    public javax.swing.JTextField edtProduto;
    public javax.swing.JTextField edtQuantidade;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

    private void LimpaTela() {
        edtCodigo.setText("");
        edtProduto.setText("");
        edtCodFabricante.setText("");
        edtFabricante.setText("");
        edtCodClassificacao.setText("");
        edtClassificacao.setText("");
        edtPrecoCusto.setText("");
        edtPrecoVenda.setText("");
        edtEstoqueMinimo.setText("");
        edtQuantidade.setText("");
    }
}
